package com.aaa.controller.sas;

import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.sas.Page;
import com.aaa.entity.sas.TSasSub;
import com.aaa.service.sas.TSasSubService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("tSasSub")

public class TSasSubController {
    @Autowired
    private TSasSubService tSasSubService;
    @Resource
    private TSasSubService fileService;
    @PostMapping(value ="/import")
    @ResponseBody
    public LayData storageService(MultipartFile file){
        fileService.dealFile(file);
        return new LayData(true);
    }
    @GetMapping
    @ResponseBody
    public LayData getAllSub(MyPage myPage){
        return new LayData(fileService.getAll(myPage));
    }
    @GetMapping("index")
    public String getIndexAllsub(MyPage myPage, HttpServletRequest request){
        myPage.setLimit(30);
        myPage.setPage(1);
        PageInfo all=fileService.getAll(myPage);
        request.setAttribute("allsub",all);
        return "/sas/index";
    }
    @PostMapping("del")
    @ResponseBody
    public LayData del(TSasSub tSasSub){
//        删除试题
        boolean del = tSasSubService.del(tSasSub);
        return new LayData(del);
    }
    @PostMapping("edit")
    @ResponseBody
    public LayData edit(TSasSub tSasSub){
//        添加和编辑共用
        boolean b = tSasSubService.updEdit(tSasSub);
        return new LayData(b);
    }
    /*
    查询SAS试题
 */
    @GetMapping("queryAll")
    @ResponseBody
    public LayData queryAll(Page page, TSasSub tSasSub){
        PageInfo pageInfo = tSasSubService.queryAll(page,tSasSub);
        return new LayData(pageInfo);
    }

}
